﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data;
using System.Data.SqlClient;

using SIPO.Library;
using SIPO.Library.DomainObject.Transaction;
using SIPO.Library.Enum;
using SIPO.Library.Interfaces;
using SIPO.Library.DomainObject.Administration.Catalog;

namespace SIPO.Library.DataAccess.Transaction
{
    public partial class recAdjusRepo 
    {
    
        public bool SaveFromAdjustRecon(recAdjus domain)
        {
            bool result = false;
            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "INSERT INTO transactions.recAdjus(TransId, TransBankId, AdjustmentTypeID, AdjustmentTypeName, AdjusValue, AdjusDate, IsPosting, CreatedBy, CreatedDate, UpdatedBy, UpdatedDate) VALUES(@TransId, @TransBankId, @AdjustmentTypeID, @AdjustmentTypeName, @AdjusValue, @AdjusDate, @IsPosting, @CreatedBy, @CreatedDate, @UpdatedBy, @UpdatedDate)";
                    cmd.CommandType = CommandType.Text;
                    cmd.Parameters.Add("@TransId", SqlDbType.VarChar).Value = (object)domain.TransId ?? DBNull.Value;

                    if(domain.TransBankId == null)
                        cmd.Parameters.Add("@TransBankId", SqlDbType.VarChar).Value = "";
                    else
                        cmd.Parameters.Add("@TransBankId", SqlDbType.VarChar).Value = domain.TransBankId;

                    
                    cmd.Parameters.Add("@AdjustmentTypeID", SqlDbType.Int).Value = (object)domain.AdjustmentTypeID ?? DBNull.Value;
                    cmd.Parameters.Add("@AdjustmentTypeName", SqlDbType.VarChar).Value = (object)domain.AdjustmentTypeName ?? DBNull.Value;
                    cmd.Parameters.Add("@AdjusValue", SqlDbType.Decimal).Value = (object)domain.AdjusValue ?? DBNull.Value;
                    cmd.Parameters.Add("@AdjusDate", SqlDbType.DateTime).Value = (object)domain.AdjusDate ?? DBNull.Value;
                    cmd.Parameters.Add("@IsPosting", SqlDbType.Bit).Value = (object)domain.IsPosting ?? DBNull.Value;
                    cmd.Parameters.Add("@CreatedBy", SqlDbType.VarChar).Value = (object)domain.CreatedBy ?? DBNull.Value;
                    cmd.Parameters.Add("@CreatedDate", SqlDbType.DateTime).Value = (object)domain.CreatedDate ?? DBNull.Value;
                    cmd.Parameters.Add("@UpdatedBy", SqlDbType.VarChar).Value = (object)domain.UpdatedBy ?? DBNull.Value;
                    cmd.Parameters.Add("@UpdatedDate", SqlDbType.DateTime).Value = (object)domain.UpdatedDate ?? DBNull.Value;

                    try
                    {
                        conn.Open();
                        cmd.ExecuteNonQuery();
                        result = true;
                    }
                    catch (Exception ex)
                    {
                        throw (ex);
                    }
                    finally
                    {
                        if (conn.State == ConnectionState.Open) conn.Close();
                    }

                }
            }
            return result;
        }
    }
}


